import type {
  ProjectAddDTOType,
  ProjectUpdateDTOType,
  ProjectSearchDTOType,
} from '@/resources/interface/project/ProjectTypes.ts'
import type { TableColumn } from '@/components/CommonTable.vue'
import { ComponentEnum, type FormItemConfig } from '@/components/CommonDialogForm.vue'
import { RoleUtils } from '@/utils/RoleUtils.ts'
import ArrayUtils from '@/utils/ArrayUtils.ts'
import { reactive } from 'vue'

/**
 * 题目表 参数对象
 */
export class ProjectParams {
  /**
   * 表单参数
   */
  static formColumn: FormItemConfig[] = [
    {
      label: '题目标题',
      prop: 'title',
      type: ComponentEnum.INPUT,
      field: 'title',
    },
    {
      label: '题目描述',
      prop: 'description',
      type: ComponentEnum.INPUT,
      field: 'description',
      attribute: {
        type: 'textarea',
        rows: 4,
        showWordLimit: true,
        maxlength: 400,
        showCount: true,
        placeholder: '请输入题目描述',
        clearable: true,
        autosize: {
          minRows: 4,
          maxRows: 8,
        },
        resize: 'vertical',
        style: {
          width: '100%',
        },
      },
    },
    {
      label: '题目要求',
      prop: 'requirements',
      type: ComponentEnum.INPUT,
      field: 'requirements',
      attribute: {
        type: 'textarea',
        rows: 4,
        showWordLimit: true,
        maxlength: 400,
        showCount: true,
        placeholder: '请输入题目描述',
        clearable: true,
        autosize: {
          minRows: 4,
          maxRows: 8,
        },
        resize: 'vertical',
        style: {
          width: '100%',
        },
      },
    },
    {
      label: '题目状态',
      prop: 'status',
      type: ComponentEnum.SELECT,
      field: 'status',
      options: [
        {
          label: '启用',
          value: 0,
        },
        {
          label: '禁用',
          value: 1,
        },
      ],
    },
    {
      label: '最大可选人数',
      prop: 'maxCapacity',
      type: ComponentEnum.INPUT_NUMBER,
      field: 'maxCapacity',
    },
  ]
  /**
   * 表格参数
   */
  static tableColumn: TableColumn[] = [
    {
      label: '发布教师名称',
      field: 'teacherName',
    },
    {
      label: '题目标题',
      field: 'title',
      template: {
        tooltip: {
          length: 20,
        },
      },
    },
    {
      label: '题目描述',
      field: 'description',
      template: {
        tooltip: {
          length: 20,
        },
      },
    },
    {
      label: '题目要求',
      field: 'requirements',
    },
    {
      label: '题目状态',
      field: 'status',
      formatter(row) {
        return row.status === 0 ? '启用' : '禁用'
      },
    },
    {
      label: '最大可选人数',
      field: 'maxCapacity',
    },
    {
      label: '当前已选人数',
      field: 'currentSelected',
    },
    {
      label: '发布时间',
      field: 'releaseTime',
    },
    {
      label: '操作',
      field: 'right',
      attribute: {
        fixed: 'right',
        width: '200px',
      },
      template: {
        options: [
          {
            icon: 'edit',
            type: 'primary',
            size: 'small',
            method: 'update',
            show: () => RoleUtils.verifyRole([1, 3]),
          },
          {
            icon: 'delete',
            type: 'danger',
            size: 'small',
            method: 'remove',
            show: () => RoleUtils.verifyRole([1, 3]),
          },
          {
            type: 'success',
            size: 'small',
            method: 'apply',
            label: '申请',
            show: () => RoleUtils.verifyRole([2]),
          },
        ],
      },
    },
  ]
  /**
   * 添加对象
   */
  static addDTO: ProjectAddDTOType = {
    title: '',
    description: '',
    requirements: '',
    status: 0,
    maxCapacity: 0,
    currentSelected: 0,
  }
  /**
   * 修改对象
   */
  static updateDTO: ProjectUpdateDTOType = {
    id: 0,
    teacherId: 0,
    title: '',
    description: '',
    requirements: '',
    status: 0,
    maxCapacity: 0,
    currentSelected: 0,
    releaseTime: '',
  }
  /**
   * 查询对象
   */
  static searchDTO: ProjectSearchDTOType = {
    title: '',
    page: {
      current: 1,
      size: 20,
    },
  }
}
